package com.shopping.dao.Impl;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.shopping.model.Carts;

public interface CartsDao {

	@Select("select ifnull(sum(amount), 0) from carts where user_id = #{userId}")
	int selectSumAmountByUserId(@Param("userId") int userId);

	//加入购物车
	@Insert("insert into carts values(null, 1, #{goodId}, #{userId})")
	boolean save(@Param("goodId") int goodId, @Param("userId") int userId);

	//根据用户ID查询该用户购物车订单信息
	@Select("select * from carts where user_id = #{userId}")
	List<Carts> selectListByUserId(@Param("userId") int userId);

	//将某个用户的所有已选商品删除掉。
	@Update("delete from carts where user_id=#{userId}")
	void deleteByUserId(int userId);

}
